package com.zm.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class R<T> {
    private static final String SUCCESS = "success";
    private static final String ERROR = "error";

    private String status; // 表示请求是否成功成功

    private String msg; // 如果请求失败，失败原因

    private T data; // 响应的数据

    public static R success(){
        return new R(SUCCESS, null, null);
    }
    public static R success(Object data){
        return new R(SUCCESS,null,data);
    }
    public static R error(String msg){
        return new R(ERROR,msg,null);
    }

    public static R write(Object targer){
        if (targer instanceof Boolean){
            Boolean flag = (Boolean) targer;
            if (flag){
                return success();
            }else {
                return error("操作失败");
            }
        }
        return error(null);
    }
}
